package com.xingkeduo.business.operation.service;

import com.xingkeduo.dao.database.DatabaseAccessObject;
import com.xingkeduo.pojo.query.PictureQuery;
import com.xingkeduo.pojo.table.PictureTable;
import com.xingkeduo.util.pojo.domain.Page;
import com.xingkeduo.util.tool.CommonUtil;
import com.xingkeduo.util.tool.IdentityUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 文件概述
 *
 * @author chenxingda <chenxingda@xingkeduo.com>
 * @version id:v0.1 2019年4月13日 14:34:51
 * @package BeautyOS
 * @copyright Copyright (c) XKD 2019
 */
@Component
public class PictureService {
    private static final String NAMESPACE = PictureTable.class.getSimpleName();

    @Resource(name = "mysqlOperationDao")
    private DatabaseAccessObject<PictureTable, PictureQuery> dao;

    //查询一条
    public PictureTable selectById(long id) throws Throwable {
        PictureTable pictureTable = dao.select(NAMESPACE, id);
        if (!CommonUtil.isEmpty(pictureTable))
            return pictureTable;
        return null;
    }

    //查询多条
    public List<PictureTable> selectLists(PictureQuery vendorQuery) throws Throwable {
        List<PictureTable> pictureTableList = dao.select(NAMESPACE, vendorQuery);
        if (!CommonUtil.isEmpty(pictureTableList))
            return pictureTableList;
        return null;
    }

    //分页查询
    public Page<PictureTable> selectPageLists(PictureQuery pictureQuery, Integer pageNo, Integer pageSize) throws Throwable {
        Page<PictureTable> pictureTablePage = dao.pageSelect(NAMESPACE,pictureQuery,pageNo,pageSize);
        return pictureTablePage;
    }

    //插入
    public int insert(PictureTable pictureTable) throws Throwable {
        pictureTable.setCode(IdentityUtil.nextId(IdentityUtil.Worker.USER));
        return dao.insert(NAMESPACE, pictureTable);
    }

    //更新
    public int update(PictureTable pictureTable) throws Throwable {
        return dao.update(NAMESPACE, pictureTable);
    }

    //删除
    public int delete(PictureTable pictureTable) throws Throwable {
        return dao.update(NAMESPACE, pictureTable);
    }
}
